﻿/** v 0.0.1 2016-09-29 by majie **/
/**
*
*/
!function(paramWindow){
	/**ajax方法**/
	paramWindow.ajax=function(options) {
        options = options || {};
        options.type = (options.type || "GET").toUpperCase();
        options.dataType = options.dataType || "json";
        var params = formatParams(options.data);

        //创建 - 非IE6 - 第一步
        if (window.XMLHttpRequest) {
            var xhr = new XMLHttpRequest();
        } else { //IE6及其以下版本浏览器
            var xhr = new ActiveXObject('Microsoft.XMLHTTP');
        }

        //接收 - 第三步
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4) {
                var status = xhr.status;
                if (status >= 200 && status < 300) {
                    options.success && options.success(xhr.responseText, xhr.responseXML);
                } else {
                    options.fail && options.fail(status);
                }
            }
        }

        //连接 和 发送 - 第二步
        if (options.type == "GET") {
            xhr.open("GET", options.url + "?" + params, true);
            xhr.send(null);
        } else if (options.type == "POST") {
            xhr.open("POST", options.url, true);
            //设置表单提交时的内容类型
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xhr.send(params);
        }
    }
    //格式化参数
    function formatParams(data) {
        var arr = [];
        for (var name in data) {
            arr.push(encodeURIComponent(name) + "=" + encodeURIComponent(data[name]));
        }
        arr.push(("v=" + Math.random()).replace("."));
        return arr.join("&");
    }
	paramWindow.hasClass=function(dom, className) {
		className = className.replace(/^\s|\s$/g, "")

		return (
			" " + ((dom || {}).className || "").replace(/\s/g, " ") + " "
		).indexOf(" " + className + " ") >= 0
	}
	 // dom 元素处理
    // 获取dom属性
    function getAttr( attr )
    {
        return this.getAttribute( attr );
    }
    // 设置属性
    function setAttr( attr, val )
    {
        this.setAttribute( attr, val );
 
        return this;
    };
    // 编辑元素class
    function editClass( mode, data )
    {
        var cls = getAttr.call( this, "class" ) || '';
 
        var arr = cls.split( /\s+/ );
 
        switch( mode )
        {
            case "add":
 
                return setAttr.call( this, "class", cls + " " + data );
 
            break;
 
            case "remove":
 
                for( var i = 0; i < arr.length; i++ )
                {
                    if( arr[ i ] == data )
                    {
                        arr.splice( i, 1 );
                    }
                };
 
                var cls = arr.join( " " );
 
                cls = cls.replace( /^\s|\s$/g, "" );
 
                // cls = cls == "" ? null : cls;
 
                return setAttr.call( this, "class", cls );
 
            break;
 
            default:
 
                console.log( "EditClass mode error!" );
 
                return this;
 
            break;
        }
    }
    // 添加class
    paramWindow.addClass=function( cls ){
        return editClass.call( this, "add", cls );
    }
    // 删除class
    paramWindow.removeClass=function( cls )
    {
        return editClass.call( this, "remove", cls );
    }
}(window);
!function(paramWindow) {
	/**绑定回退事件**/
	var goBackElement=document.getElementById('goBack');
	goBackElement.onclick = function(){
		window.history.go(-1);
	}
	/**接触按钮事件**/
	var ServId = sessionStorage.getItem("userOrder_theOrderServId");
	var orderId = sessionStorage.getItem("userOrder_theorderId");
	var linkNbr = sessionStorage.getItem("userOrder_linkNbr");
	var linkMan = sessionStorage.getItem("userOrder_theOrderlinkMan");
	var paramDomItem=new Array();
	paramDomItem.push('<div class="order-info-box bdb-1px"><div class="mt  cf"><div class="floatL">');
	paramDomItem.push('工单号:<span class="s1-num">');
	paramDomItem.push(orderId);
	paramDomItem.push('</span>');
	paramDomItem.push(' </div></div></div>');
	paramDomItem.push('<a id="orderTrack" href="" class="a-link bdt-1px"><div class="mc">');
	paramDomItem.push('<div class="s1-l"><div class="cf car-box">用户ID：');
	paramDomItem.push('<p class="flex-content">');
	paramDomItem.push(ServId);
	paramDomItem.push('</p>');
	paramDomItem.push('</div>');
	paramDomItem.push('</div></div></a>');
	paramDomItem.push('<div class="signet" id="sigentID" ></div> ');
	var searchListElement =document.getElementById('userCountactOfTask-1');
	searchListElement.innerHTML+=paramDomItem.join("");

	var paramDomItem=new Array();
	paramDomItem.push('<div class="m step2-in "><div class="mt"><div class="s2-name">');
	paramDomItem.push('<i></i>');

	paramDomItem.push(linkMan);
	paramDomItem.push('</div> ');
	paramDomItem.push('<div class="s2-phone">');
	paramDomItem.push("<i></i>");
	paramDomItem.push(linkNbr);
	paramDomItem.push('</div> ');
	paramDomItem.push('</div></div>');
	paramDomItem.push('<b class="s2-borderT"></b>');
	paramDomItem.push('<b class="s2-borderB"></b>');

//	paramDomItem.push('<div class="step4-contact bdb-1px" id="dongdong" style="display: none;">');
//	paramDomItem.push('<a class="contact-a" id="contactCustom"> <i></i>');
//	paramDomItem.push("接触成功");
//	paramDomItem.push('</div> ');
	var searchListElement =document.getElementById('userCountactOfTask-2');
	searchListElement.innerHTML+=paramDomItem.join("");
	
	var theOrderTouchResult=document.getElementsByClassName('theOrderTouchResult');
	var IsSuccess;
	for(var i=0;i<theOrderTouchResult.length;i++){
		theOrderTouchResult[i].onclick = function(){
		    var theOrderTouchResult1=document.getElementsByClassName('theOrderTouchResult');
			for(var i=0;i<theOrderTouchResult1.length;i++){
				paramWindow.removeClass.call(theOrderTouchResult1[i], 'isSuccesstheOrderTouchResult');
			}
			paramWindow.addClass.call(this, 'isSuccesstheOrderTouchResult');
		}
	}
	var contactCustomSuccess =document.getElementById('contactCustomSuccess');
	

	var subTouchOfOrder =document.getElementById('subTouchOfOrder');
	subTouchOfOrder.onclick = function(){
		var theOrderTouchResult1=document.getElementsByClassName('isSuccesstheOrderTouchResult');
		IsSuccess = theOrderTouchResult1[0].getAttribute("touchSuccessResult");
		var subTouchOfOrder =document.getElementById('subTouchOfOrder');
		var memo = subTouchOfOrder.value;
		paramWindow.ajax({
			//请求地址
			url: "http://133.37.253.32:7002/ims/policy_library_index_show!backListTouchForMobile.action?",              
			type: "POST",//请求方式
			data: {"servId":ServId,"orderId":orderId,"IsSuccess":IsSuccess,"memo":memo},//请求参数
			dataType: "json",
			success: function (response, xml) {
				var obj =  eval("(" + response + ")");
				console.log(obj.output.result);
				if(obj.output.result=="true"){
					var sigentID =  document.getElementById('sigentID');
					paramWindow.removeClass.call(sigentID, 'sigent');
					paramWindow.addClass.call(sigentID, 'signet-contact');
				}
			},
			fail: function (status) {
				// 此处放失败后执行的代码
			}
		});
	}
	
} (window);